﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.OtbData.Search;


namespace University.Workshop.Presentation.OTBData
{
    /// <summary>
    /// Interaction logic for SearchOtbData.xaml
    /// </summary>
    public partial class SearchOtbData : Page, ISearchOtbDataView
    {
        PresenterSearchOtbData pSearchOtbData;
        public SearchOtbData()
        {
            InitializeComponent();
            pSearchOtbData = new PresenterSearchOtbData(this);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Datos OTB";
        }

        #region Fields
        public string OtbName
        {
            get
            {
                return nameTxt.Text;
            }
        }

        public string Managment
        {
            get 
            {
                return managmentTxt.Text;
            }
        }

        public string PresidentNamesRelative
        {
            get
            {
                return presidentnamesTxt.Text;
            }
        }

        public string PresidentLastNamesRelative
        {
            get
            {
                return presidentnamesTxt.Text;
            }
        }

        public ICollection<Model.OtbData> OtbsFinded
        {
            set
            {
                OtbdataFindeddDgv.ItemsSource = null;
                OtbdataFindeddDgv.ItemsSource = value;
            }
        }
        #endregion

        #region Validation
        private void managmentTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsDigit(ch) || ch.Equals('-'));
            }
        }
        #endregion

        #region Buttons Actions
        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchOtbData.SearchOtbData();
        }

        private void ShowOtbDataBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new OTBData.Read.ReadOtbDataPrincipal((Model.OtbData)OtbdataFindeddDgv.SelectedItem));
        }
        #endregion

        #region ErrorMessage
        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }
        #endregion

        
    }
}
